﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using ExtAspNet;
using Sale_Operation;
using Sale_Model;
using Sale_Common;

namespace SaleSystem.Other
{
    public partial class frm_WorkPlanDetailList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
                GetWorkPlan();
        }
                /// <summary>
        /// 获取需要提醒的日程信息
        /// </summary>
        private void GetWorkPlan()
        {
            dtWrokList = null;
            GetWorkPlanTitle(0);
        }
        private void GetWorkPlanTitle(int index)
        {
            DataTable dt = dtWrokList;
            if (dt.Rows.Count <= 0)
            {                
                return;
            }
            if (index >= dt.Rows.Count)
            {
                index = 0;
                iCurrentIndex = 0;
            }
            if (index <= 0)
            {
                iCurrentIndex = 0;
                index = 0;
            }
            DataRow dr = dt.Rows[index];
           
            lb_WPlan_Title.Text = ValueHandler.GetStringValue(dr["WPlan_Title"]);
            lb_WPlan_Content.Text = ValueHandler.GetStringValue(dr["WPlan_Content"]);
            lb_Time.Text = DateTime.Parse(dr["WPlan_StartTime"].ToString()).ToString("yyyy-MM-dd") + " 至 " + DateTime.Parse(dr["WPlan_EndTime"].ToString()).ToString("yyyy-MM-dd");
            // WorkForm.Hidden = false; 
        }
        protected void lb_WPlan_Content_Click(object sender, EventArgs e)
        {
            
            win_Content.Hidden = false;
            win_Content.IFrameUrl = "frm_WorkPlanEdit.aspx?Id=" + ValueHandler.GetIntNumberValue(dtWrokList.Rows[iCurrentIndex]["WPlan_Id"]);
            win_Content.Title = "编辑-" + ValueHandler.GetStringValue(dtWrokList.Rows[iCurrentIndex]["WPlan_Title"]);
        }
        protected void lb_PreviorClick(object sender, EventArgs e)
        {
            iCurrentIndex--;
            GetWorkPlanTitle(iCurrentIndex);
        }
        protected void lb_NextClick(object sender, EventArgs e)
        {
            iCurrentIndex++;
            GetWorkPlanTitle(iCurrentIndex);
        }
        #region Property
        public DataTable dtWrokList
        {
            get
            {
                if (ViewState["dtWrokList"] != null)
                    return (DataTable)ViewState["dtWrokList"];
                else
                {
                    WorkPlanOp workManager = new WorkPlanOp();
                    DataTable dt = workManager.GetList("WPlan_WarningTime<='" + System.DateTime.Now.ToString("yyyy-MM-dd") + "' AND WPlan_Enable=1 AND WPlan_State=0 AND A.State=1 ");
                    ViewState["dtWrokList"] = dt;
                    return dt;
                }
            }
            set
            {
                ViewState["dtWrokList"] = value;
            }
        }
        public int iCurrentIndex
        {
            get
            {
                if (ViewState["iCurrentIndex"] != null)
                    return ValueHandler.GetIntNumberValue(ViewState["iCurrentIndex"]);
                else
                    return 0;
            }
            set
            {
                ViewState["iCurrentIndex"] = value;
            }
        }
        #endregion
    }
}
